package io.renren.modules.xm.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.sys.controller.AbstractController;
import io.renren.modules.xm.entity.ProdCategoryEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.xm.entity.MasterWorkerEntity;
import io.renren.modules.xm.service.MasterWorkerService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 技师表
 *
 * @author liuyonggang
 * @email 544872316@qq.com
 * @date 2018-06-28 15:59:53
 */
@RestController
@RequestMapping("xm/masterworker")
public class MasterWorkerController extends AbstractController {
    @Autowired
    private MasterWorkerService masterWorkerService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("xm:masterworker:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = masterWorkerService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @RequestMapping("/select")
    public R select(){
        List<MasterWorkerEntity> list = masterWorkerService.selectList(null);
        return R.ok().put("list", list);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("xm:masterworker:info")
    public R info(@PathVariable("id") Integer id){
        MasterWorkerEntity masterWorker = masterWorkerService.selectById(id);

        return R.ok().put("masterWorker", masterWorker);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("xm:masterworker:save")
    public R save(@RequestBody MasterWorkerEntity masterWorker){
        masterWorkerService.insert(masterWorker);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("xm:masterworker:update")
    public R update(@RequestBody MasterWorkerEntity masterWorker){
        ValidatorUtils.validateEntity(masterWorker);
        masterWorkerService.updateAllColumnById(masterWorker);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("xm:masterworker:delete")
    public R delete(@RequestBody Integer[] ids){
        masterWorkerService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
